﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Media;

namespace Reuse.WP8.Extensions {
	/// <summary>
	/// Helper class with methods to manipulate the theme in Windows Phone
	/// </summary>
	public static class ThemeHelper {
		/// <summary>
		/// Forces the light theme in Windows Phone on all controls affected with theme change, by replacing the color resources for the light color scheme.
		/// </summary>
		/// <param name="app">The Application object of the application</param>
		public static void ForceLightTheme( this Application app ) {

			( app.Resources["PhoneBackgroundBrush"] as SolidColorBrush ).Color = Color.FromArgb( 255, 255, 255, 255 );
			( app.Resources["PhoneBorderBrush"] as SolidColorBrush ).Color = Color.FromArgb( 153, 0, 0, 0 );
			( app.Resources["PhoneChromeBrush"] as SolidColorBrush ).Color = Color.FromArgb( 255, 221, 221, 221 );
			( app.Resources["PhoneContrastBackgroundBrush"] as SolidColorBrush ).Color = Color.FromArgb( 222, 0, 0, 0 );
			( app.Resources["PhoneContrastForegroundBrush"] as SolidColorBrush ).Color = Color.FromArgb( 255, 255, 255, 255 );
			( app.Resources["PhoneDisabledBrush"] as SolidColorBrush ).Color = Color.FromArgb( 77, 0, 0, 0 );
			( app.Resources["PhoneForegroundBrush"] as SolidColorBrush ).Color = Color.FromArgb( 222, 0, 0, 0 ); 
			( app.Resources["PhoneInactiveBrush"] as SolidColorBrush ).Color = Color.FromArgb( 51, 0, 0, 0 );
			( app.Resources["PhoneInverseBackgroundBrush"] as SolidColorBrush ).Color = Color.FromArgb( 255, 221, 221, 221 );
			( app.Resources["PhoneInverseInactiveBrush"] as SolidColorBrush ).Color = Color.FromArgb( 255, 229, 229, 229 );

			( app.Resources["PhoneRadioCheckBoxCheckBrush"] as SolidColorBrush ).Color = Color.FromArgb( 222, 0, 0, 0 );
			( app.Resources["PhoneRadioCheckBoxCheckDisabledBrush"] as SolidColorBrush ).Color = Color.FromArgb( 77, 0, 0, 0 ); 
			( app.Resources["PhoneRadioCheckBoxBrush"] as SolidColorBrush ).Color = Color.FromArgb( 77, 0, 0, 0 );
			( app.Resources["PhoneRadioCheckBoxDisabledBrush"] as SolidColorBrush ).Color = Color.FromArgb( 0, 0, 0, 0 );
			( app.Resources["PhoneRadioCheckBoxPressedBorderBrush"] as SolidColorBrush ).Color = Color.FromArgb( 222, 0, 0, 0 );
			( app.Resources["PhoneRadioCheckBoxPressedBrush"] as SolidColorBrush ).Color = Color.FromArgb( 0, 0, 0, 0 );

			( app.Resources["PhoneSemitransparentBrush"] as SolidColorBrush ).Color = Color.FromArgb( 170, 255, 255, 255 );
			( app.Resources["PhoneSubtleBrush"] as SolidColorBrush ).Color = Color.FromArgb( 102, 0, 0, 0 );

			( app.Resources["PhoneTextBoxBrush"] as SolidColorBrush ).Color = Color.FromArgb( 38, 0, 0, 0 );
			( app.Resources["PhoneTextBoxEditBackgroundBrush"] as SolidColorBrush ).Color = Color.FromArgb( 0, 0, 0, 0 );
			( app.Resources["PhoneTextBoxEditBorderBrush"] as SolidColorBrush ).Color = Color.FromArgb( 222, 0, 0, 0 );
			( app.Resources["PhoneTextBoxForegroundBrush"] as SolidColorBrush ).Color = Color.FromArgb( 222, 0, 0, 0 );
			( app.Resources["PhoneTextBoxReadOnlyBrush"] as SolidColorBrush ).Color = Color.FromArgb( 46, 0, 0, 0 );
			( app.Resources["PhoneTextBoxSelectionForegroundBrush"] as SolidColorBrush ).Color = Color.FromArgb( 255, 255, 255, 255 );
			( app.Resources["PhoneTextCaretBrush"] as SolidColorBrush ).Color = Color.FromArgb( 222, 0, 0, 0 );
		}
		/// <summary>
		/// Forces the dark theme in Windows Phone on all controls affected with theme change, by replacing the color resources for the dark color scheme.
		/// </summary>
		/// <param name="app">The Application object of the application</param>
		public static void ForceDarkTheme( this Application app ) {

			( app.Resources["PhoneBackgroundBrush"] as SolidColorBrush ).Color = Color.FromArgb( 255, 0, 0, 0 );
			( app.Resources["PhoneBorderBrush"] as SolidColorBrush ).Color = Color.FromArgb( 191, 255, 255, 255 );
			( app.Resources["PhoneChromeBrush"] as SolidColorBrush ).Color = Color.FromArgb( 255, 31, 31, 31 );
			( app.Resources["PhoneContrastBackgroundBrush"] as SolidColorBrush ).Color = Color.FromArgb( 255, 255, 255, 255 );
			( app.Resources["PhoneContrastForegroundBrush"] as SolidColorBrush ).Color = Color.FromArgb( 255, 0, 0, 0 );
			( app.Resources["PhoneDisabledBrush"] as SolidColorBrush ).Color = Color.FromArgb( 102, 255, 255, 255 );
			( app.Resources["PhoneForegroundBrush"] as SolidColorBrush ).Color = Color.FromArgb( 255, 255, 255, 255 );
			( app.Resources["PhoneInactiveBrush"] as SolidColorBrush ).Color = Color.FromArgb( 33, 255, 255, 255 );
			( app.Resources["PhoneInverseBackgroundBrush"] as SolidColorBrush ).Color = Color.FromArgb( 255, 255, 255, 255 );
			( app.Resources["PhoneInverseInactiveBrush"] as SolidColorBrush ).Color = Color.FromArgb( 255, 204, 204, 204 );

			( app.Resources["PhoneRadioCheckBoxCheckBrush"] as SolidColorBrush ).Color = Color.FromArgb( 255, 0, 0, 0 );
			( app.Resources["PhoneRadioCheckBoxCheckDisabledBrush"] as SolidColorBrush ).Color = Color.FromArgb( 6, 96, 0, 0 );
			( app.Resources["PhoneRadioCheckBoxBrush"] as SolidColorBrush ).Color = Color.FromArgb( 191, 255, 255, 255 );
			( app.Resources["PhoneRadioCheckBoxDisabledBrush"] as SolidColorBrush ).Color = Color.FromArgb( 102, 255, 255, 255 );
			( app.Resources["PhoneRadioCheckBoxPressedBorderBrush"] as SolidColorBrush ).Color = Color.FromArgb( 255, 255, 255, 255 );
			( app.Resources["PhoneRadioCheckBoxPressedBrush"] as SolidColorBrush ).Color = Color.FromArgb( 255, 255, 255, 255 );

			( app.Resources["PhoneSemitransparentBrush"] as SolidColorBrush ).Color = Color.FromArgb( 170, 0, 255, 255 );
			( app.Resources["PhoneSubtleBrush"] as SolidColorBrush ).Color = Color.FromArgb( 153, 255, 255, 255 );

			( app.Resources["PhoneTextBoxBrush"] as SolidColorBrush ).Color = Color.FromArgb( 191, 255, 255, 255 );
			( app.Resources["PhoneTextBoxEditBackgroundBrush"] as SolidColorBrush ).Color = Color.FromArgb( 255, 255, 255, 255 );
			( app.Resources["PhoneTextBoxEditBorderBrush"] as SolidColorBrush ).Color = Color.FromArgb( 255, 255, 255, 255 );
			( app.Resources["PhoneTextBoxForegroundBrush"] as SolidColorBrush ).Color = Color.FromArgb( 255, 0, 0, 0 );
			( app.Resources["PhoneTextBoxReadOnlyBrush"] as SolidColorBrush ).Color = Color.FromArgb( 119, 0, 0, 0 );
			( app.Resources["PhoneTextBoxSelectionForegroundBrush"] as SolidColorBrush ).Color = Color.FromArgb( 255, 255, 255, 255 );
			( app.Resources["PhoneTextCaretBrush"] as SolidColorBrush ).Color = Color.FromArgb( 255, 0, 0, 0 );
		}
	}
}
